<template>
    <div class="processMatters">
        <div class="processMatters-top"><my-icon type="iconflowChart" class="process-icon"/><span class="processMatters-top-name">{{ i18n("bpmItem","流程事项") }}</span></div>
        <div class="processMatters-list rx-roll-container">
            <div class="processMatters-item" :title="$i18(item.name,'菜单名称')" @click="jumpToList(item)" v-for="(item,index) in initializeData">
                <div class="processMatters-item-le" :style="{backgroundImage:item.color}">
                    <my-icon :type="item.icon"></my-icon>
                </div>
                <div class="processMatters-item-ri">
                    <span class="processMatters-item-name">{{ $i18(item.name,'菜单名称')}}</span>
                    <span class="processMatters-item-count">{{item.count}}</span>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import {Util} from '@lowcode/jpaas-base-lib';
import processMatters from "@/views/modules/column/processMatters/processMatters";
import useMain from "@/stores/useMain.js";
import { mapState,mapActions } from 'pinia'

export default {
    name: "processMatters",
    data(){
        return{
            initializeData:[
                {
                    name:this.i18n('myTasks','我的待办'),
                    icon:'icondaiban',
                    url:'MyBpmTaskList',
                    count:0,
                    color:'linear-gradient(-30deg,'+'#4285f4 0%,'+'#70a8ff 100%)'
                },{
                    name:this.i18n('myTrack','我的跟踪'),
                    url:'MyTracked',
                    count:0,
                    icon:'iconVue3jpaas-icon_genzong',
                    color:'linear-gradient(-30deg,'+'#fe9525 0%,'+'#feb664 100%)'
                },{
                    name:this.i18n('initiation','我的发起'),
                    url:"MyBpmInstList",
                    count:0,
                    icon:'iconVue3jpaas-icon_shenpilishi',
                    color:'linear-gradient(-30deg,'+'#41c067 0%,'+'#80e17b 100%)'
                },{
                    name:this.i18n('myDone','我的已办'),
                    url:'MyApprovedTasks',
                    count:0,
                    icon:'icontask',
                    color:'linear-gradient(-30deg,'+'#12b8d6 0%,'+'#12dad0 100%)'
                },{
                    name:this.i18n('myCC','我的抄送'),
                    url:'myTurnTo',
                    count:0,
                    icon:'iconVue3jpaas-icon_publish',
                    color:'linear-gradient(-30deg,'+'#41c067 0%,'+'#80e17b 100%)'
                },{
                    name:this.i18n('myPending','我的挂起'),
                    url:'myPending',
                    count:0,
                    icon:'iconguaqi',
                    color:'linear-gradient(-30deg,'+'#fa5840 0%,'+'#ff9891 100%)'
                },{
                    name:this.i18n('myTransfer','我的转办'),
                    url:'MyTransOutTask',
                    count:0,
                    icon:'iconfile-done',
                    color:'linear-gradient(-30deg,'+'#12b8d6 0%,'+'#12dad0 100%)'
                },{
                    name:this.i18n('receivedTransfer','收到的转办'),
                    url:'MyReceiveTask',
                    count:0,
                    icon:'iconVue3jpaas-icon_huifu',
                    color:'linear-gradient(-30deg,'+'#4285f4 0%,'+'#70a8ff 100%)'
                },{
                    name:this.i18n('receivedCC','收到的抄送'),
                    url:'myReceiveCopy',
                    count:0,
                    icon:'iconsmallscreen',
                    color:'linear-gradient(-30deg,'+'#7a61fb 0%,'+'#b892ff 100%)'
                },{
                    name:this.i18n('myAttention','我的关注'),
                    url:'MyConcern',
                    count:0,
                    icon:'iconstar-collection',
                    color:'linear-gradient(-30deg,'+'#fe9525 0%,'+'#feb664 100%)'
                },{
                    name:this.i18n('asynTask','异步任务'),
                    url:'asyncTask',
                    count:0,
                    icon:'iconzhuanban',
                    color:'linear-gradient(-30deg,'+'#7a61fb 0%,'+'#b892ff 100%)'
                }
            ]
        }
    },
    computed: {
        ...mapState(useMain, [ 'navigations','appKey','curApp'])
    },
    created(){
        this.getAllBpmCount()
    },
    methods:{
        ...mapActions(useMain,['setNavigations','setNavigation']),
        i18n(name, text, key) {
            return this.$ti18(name, text, "ProcessPortal", key);
        },
        getAllBpmCount(){
            var self_=this;
            processMatters.getAllBpmCount().then(res=>{
                for (let data of self_.initializeData){
                    data.count=res.data[data.url]
                }
            })
        },
        jumpToList(item){
            debugger
            let {appId,appType} = this.curApp ;
            let obj = {
                collapsed:true,
                key:item.url,
                menuKey:item.url,
                title:item.name,
                name:item.name,
                showType:'URL',
                //系统应用不需要拼接appId
                appId:appId,
                microApp:'homeIndex',
                /*流程事项*/
                openMicroHome:'flow',
            }
            if(this.curApp && this.curApp.isMicroApp){
                this.openMain(obj);
            }
            let isIndex = this.navigations.findIndex(nav=>nav.menuKey === obj.menuKey)
            if(isIndex<0){
                this.navigations.push(obj);
            }
            this.setNavigation(obj.menuKey)
            let pathObj ={
                name: obj.menuKey,
                params: {appKey:this.appKey},
            }
            if(obj.appId){
                pathObj.query={appId:obj.appId}
            }
            this.$router.push(pathObj)
        },
        openMain(obj){
            let {appId} = this.curApp;
            //打开主应用
            let data = {
                appId,
                ...obj,
                title:obj.name,
                name:obj.name,
                menuNavType:2,
                randomKey:Util.randomId()
            }
            //触发main的事件
            window.microApp && window.microApp.dispatch(data)
        },
    }
}
</script>

<style scoped>
.process-icon{
    color: #4285f4;
    margin-right: 10px;
    font-size: 25px;
}
.processMatters-top{
    display: flex;
    align-items: center;
    height: 50px;
    line-height: 50px;
}
.processMatters-top i {
    color: #4285f4;
    font-size: 22px;
    margin-right: 12px;
}
.processMatters-top-name{
    font-size: 16px;
    color: #010101;
    font-weight: bold;
}
.processMatters{
    padding: 0px 5px 5px 20px;
    width: 100%;
    height: 100%;
    flex-direction: column;
    display: flex;
    overflow: auto;
    background-image: url('@public/image/process/processMatters.png');
    background-position: right bottom;
    background-repeat: no-repeat;
}
.processMatters-list{
    display: grid;
    grid-template-columns: repeat(auto-fill,minmax(162px,1fr));
    grid-gap: 15px;
    padding: 10px 5px 10px 0;
}
.processMatters-item{
    height: 80px;
    background-color: rgb(242,246,255);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: left;
    padding: 16px;
    box-sizing: border-box;
    overflow: hidden;
    cursor: pointer;
    font-size: 26px;
}
.processMatters-item-le{
    width: 48px;
    height: 48px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 16px;
    overflow: hidden;
    box-sizing: border-box;
}
.processMatters-item-le i{
    color: white;
    width: 48px;
    text-align: center;
    font-size: 30px;
}
.processMatters-item-name{
    font-size: 12px;
    line-height: 20px;
    color: #010101;
    opacity: 0.85;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    width: 60px;
}
.processMatters-item-count{
    color: #000000;
    font-size: 18px;
    font-weight: bold;
    line-height: 20px;
}
.processMatters-item-ri{
    display: flex;
    flex-direction: column;
}
</style>
